Engineering Tips
Volume Number: 4
Issue Number: 2
Column Tag: The Workstation Mac
Tips for Engineering Applications 
By Paul Zarchan, Cambridge, Mass.
With the advent of the Mac 2 and many third party Macintosh speed enhancers
many engineers will now consider using the Macintosh for serious computation. Many
of these engineers are currently using mainframe computers where the graphics
environment is primitive or nonexistant and where CPU time is expensive and has
little to do with turn around time. The purpose of this article is to give a few pointers
in BASIC and FORTRAN, the languages with which engineers will initially feel most
comfortable, on how to make effective use of the Macintosh for both graphics and speed.
Many engineers have heard that programming on the Mac is difficult and unlike
mainframe programming. This is true if the end result is a commercial product.
Making a program user friendly may cause simple code to grow by more than an order
of magnitude. Using the various Macintosh toolbox routines requires the learning of a
new language and a new way of thinking. However ordinary engineering applications
are quite easy to program on the Mac - in fact even easier to program than on a
mainframe or other micro - because of the user friendly environment, superior
editing tools and virtually instantaneous feedback.
This article will show how engineers can modify ordinary programs, written in
FORTRAN or BASIC, which generate numerical output and enhance these programs with
the addition of a few lines of code so that they can serve as input drivers to professional
commercial graphics software. In this way their numerical output can easily be
converted to professional quality graphs and charts with little effort. They will
discover, as I did, that instantaneous graphical feedback will not only help them convey
their engineering message to others quickly but will also challenge them to modify
their original program to get even more useful information. In addition, techniques
for generating random numbers on the Mac will be discussed so that engineers can see
how easy it is to perform monte carlo and statistical analysis. Finally, for those
engineers wanting to run more complex problems on the Mac in BASIC, tips will be
given on how to speed up program execution tiime with minimal changes to the
program.
The powerful graphic commands in MS BASIC and the access to the Macintosh
toolbox in MacFortran permit the development of plotting packages in those respective
languages. However, rather than re-inventing the wheel, it is better and much easier
to use a very powerful commercial graphics package for engineers that already exists
- Cricket Graph. The purpose of this section is to show the few lines of code are
necessary to add to existing engineering programs so that the resultant output
data,whether generated in BASIC or FORTRAN, can be transferred to Cricket Graph.
Cricket Graph requires it’s numerical input to be in a tab delimited format.
Unfortuneately MS BASIC writes data to a file in comma delimited format. The simple
fix to the problem is to have BASIC write it’s output to the screen for viewing
purposes and to also write the output to the Macintosh clipboard for eventual pasting
into Cricket Graph. Listing 1 presents a sample BASIC program which computes the
expressions y=i2 and z=i3 for values of i ranging between 1 and 10. The resultant
output is written to both the screen and clipboard.
OPEN “CLIP:”FOR OUTPUT AS #1
FOR I=1 TO 10
Y=I*I
Z=I^3
PRINT I,Y,Z
WRITE #1,I,Y,Z
NEXT I
CLOSE #1
Listing 1 - Writing Output to Clipboard in BASIC
The code in boldface can be added to any program so that output can be written to
the clipboard in tab delimited format. The next step is to quit BASIC and then open
Cricket Graph and finally to use the paste command to import the data. The resultant
line plot, developed with Crickett Graph and slightly enhanced in MacDraw, is shown in
Fig. 1.
Figure 1 - Using Cricket Graph to Plot BASIC Output
With Cricket Graph the ranges on the abscissa and ordinate can be changed
quickly by double-clicking on the axis of interest. In addition, the BASIC data can be
viewed in log-log form by simply choosing the log option in Cricket Graph. Grids can
be added for additional readability. Figure 2 shows the same BASIC data viewed in
gridded log-log format.
Figure 2 - BASIC Output Viewed in Log-Log Format
A FORTRAN program can also be modified so that its ouput can also be placed in a
tabbed delimited format. This is easier to do in FORTRAN than in BASIC because it is
possible to write data to a sequential file in tabbed delimited format. In order to
illustrate the technique let’s consider the Fourier Series representation of the